<?php
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <title>Clipboard URL Grabber</title>
    <style>
        #popup {
            width: 100%;
            background-color: #fff;
            z-index: 1000;
        }
        input{
            width:50%;
            height:30px;
        }
        button{
            height:33px;
        }
    </style>
</head>
<body>
<div id="popup">
    <form>
        <input type="text" id="s_url" name="s_url" placeholder="请输入或粘贴URL">
        <button id="startGrabButton" onclick="javascript:zq()">开始抓取</button>
    </form>
</div>

<script>
    var s_url;
    $(document).ready(function () {
        navigator.clipboard.readText().then(text => {
            s_url = text;
            $("#s_url").val(text);
        });
    })

    function zq() {

        navigator.clipboard.readText().then(text => {
            s_url = text;
            alert(text)
            $("#s_url").val(text);

        });

        var url = top.window.location.href;
        var content = top.document.documentElement.outerHTML;
        var s_url = text;
        var xhr1 = new XMLHttpRequest();
        xhr1.open('POST', 'https://shop.shante.me/yunshop/au3/click.php', true);
        xhr1.setRequestHeader('Content-Type', 'application/json');
        xhr1.onreadystatechange = function () {
            if (xhr1.readyState === 4) {
                if (xhr1.status === 200) {
                    var response = JSON.parse(xhr1.responseText);
                    if (response && Array.isArray(response.images)) {
                        var xhr2 = new XMLHttpRequest();
                        xhr2.open('POST', 'http://localhost:3000/downloadimages', true);
                        xhr2.setRequestHeader('Content-Type', 'application/json');
                        xhr2.send(JSON.stringify({images: response.images}));
                    } else {
                    }
                } else {
                }
            }
        };
        xhr1.send(JSON.stringify({url: url, content: content, s_url: s_url}));
    }
</script>
</body>
</html>
